package macrochip.vison.com.gps.utils;

import android.view.View;
import android.widget.EditText;

/**
 * Created by XiaoShu
 * on 2017/8/1 16:04
 */

public class ViewUtils {
    public static float SCREEN_DENSITY = 1;

    public static String getString(EditText et){
        String srt = "";
        if (null != et) {
            srt = et.getText().toString().trim();
        }
        return srt;
    }

    public static int dp2px(float dp) {
        final float scale = SCREEN_DENSITY;
        return (int) (dp * scale + 0.5f);
    }

    public static boolean isVisible(View v){
        return v != null && v.getVisibility() == View.VISIBLE;
    }

    /**
     * 设置view 是否可用（透明度)
     * @param v
     * @param enable
     */
    public static void setEnabledByAlpha(View v, boolean enable){
        v.setEnabled(enable);
        if (enable) {
            v.setAlpha(1.0f);
        } else {
            v.setAlpha(0.3f);
        }
    }
}
